package com.website.bookshelf.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ProblemDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.server.ResponseStatusException;

@Slf4j
@RestControllerAdvice
public class AdviceController {
    @ExceptionHandler(ResponseStatusException.class)
    public ResponseEntity<ProblemDetail> statusExceptionResponseEntity(ResponseStatusException exception) {
        log.error(exception.getMessage(), exception);
        return new ResponseEntity<>(exception.getBody(), exception.getStatusCode());
    }
}
